import type { ApifoxModel, bianji, Datum, Datumbuild, EnterpriseDetail, EnterpriseListData, EnterpriseListParams, EnterpriseParams, Industry, louyuData, louyuRow, RentParams,} from '@/types/enterprise'
import service, { request } from '@/utils/reuqest'

/**
 * 获取企业列表
 * @param { page, pageSize} params
 * @returns
 */
export const getEnterpriseListAPI = (params: EnterpriseListParams) => {
  return request<EnterpriseListData>('/park/enterprise', 'GET', params)
}

export const getIndustryListAPI = () => {
  return request<Industry[]>('/park/industry', 'GET')
}
/**
 * 添加企业
 * @param {*} data
 * @returns
 */
export const createEnterpriseAPI = (data: EnterpriseParams) =>{
  return request('/park/enterprise', 'POST', data)
}

export const bianjiAPI = (data:bianji) => {
  return request('park/enterprise','PUT',data)
}

export const shanchuAPI = (id:number) => {
  return request (`/park/enterprise/${id}`,'DELETE')
}

//查看
export const chakanAPI = (id: string) => {
  return request<EnterpriseParams>(`/park/enterprise/${id}`)
}

//获取租赁频道列表
export const getRentBuildListAPI = () => {
  return request<Datumbuild[]>('/park/rent/building')
}

//提交合同
export const createRentAPI = (data: RentParams) => {
  return request('/park/enterprise/rent', 'POST', data)
}

/**
 * 获取企业下合同列表
 * @param {*} id
 * @returns
 */
export const getRentListAPI = (id: number) => {
  return request<Datum[]>(`/park/enterprise/rent/${id}`)
}

/**
 * 退租
 * @param {合同id} rentId
 * @returns
 */
export const outRentAPI = (rentId: string)=> {
  return request(`/park/enterprise/rent/${rentId}`, 'PUT')
}


/**
 * 删除合同
 * @param {合同id} rentId
 * @returns
 */
export const deleteRentAPI = (rentId: string)=> {
  return request(`/park/enterprise/rent/${rentId}`, 'DELETE')
}

/**
 * 获取企业详情
 * @param {*} id
 * @returns
 */
export const getEnterpriseDetailAPI = (id: string) => {
  return request<EnterpriseDetail>(`/park/enterprise/${id}`)
}

//下载合同文件
export const downloadContract = (id: number) => {
  // ❌ 普通的写法，解析成字符串是错误的
  //return request(`/download/${id}`)

   // ✅ 第二个范型参数为 Blob，请求配置中设置 responseType: 'blob'
  return service.request<null, Blob>({
    method: 'GET',
    url: `/download/${id}`,
    responseType:'blob'
  })
}

//获取楼宇详情
export const getlouyudAPI=(params:ApifoxModel)=> {
  return request<louyuData>('/park/building','GET',params)
}